// CWDateTime.cpp : implementation file
//

#include "stdafx.h"
#include "assit.h"
#include "CWDateTime.h"
#include "AssitTreeNode.h"


// CWDateTime

IMPLEMENT_DYNAMIC(CWDateTime, CDateTimeCtrl)

CWDateTime::CWDateTime()
{

}

CWDateTime::~CWDateTime()
{
}


BEGIN_MESSAGE_MAP(CWDateTime, CDateTimeCtrl)
	ON_WM_KILLFOCUS()
	ON_WM_KEYDOWN()
END_MESSAGE_MAP()



// CWDateTime message handlers




void CWDateTime::OnKillFocus(CWnd* pNewWnd)
{
	CDateTimeCtrl::OnKillFocus(pNewWnd);

	ShowWindow(SW_HIDE);

	CWaiTreeNode* pNode = (CWaiTreeNode*)GetParent();
	CString content = pNode->getContent();

	SYSTEMTIME sysTime = {0};
	GetTime(&sysTime);
	CString cTime;
	cTime.Format(L"<D>%d-%d-%d</D>", sysTime.wYear, sysTime.wMonth, sysTime.wDay);

	content += cTime;

	int nChar = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)content, content.GetLength(), NULL, 0, NULL, NULL);
	char* chs = new char[nChar+1];
	chs[nChar] = 0;
	WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)content, content.GetLength(), chs, nChar, NULL, NULL);
	pNode->setContent(chs);
	delete[] chs;

	// TODO: Add your message handler code here
}

void CWDateTime::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

	if(nChar == VK_RETURN)
	{
		CWaiTreeNode* pNode = (CWaiTreeNode*)GetParent();
		pNode->setEditFocus();
		return;
	}
	// TODO: Add your message handler code here and/or call default
	CDateTimeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);

}
